"""

"""

from kivy.uix.screenmanager import Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.app import App
from ..components.file_chooser import FileChooser

class UploadWindow(Screen):
    """"""
    
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.selected_file = None
        self._build_ui()
    
    def _build_ui(self):
        """"""
        main_layout = BoxLayout(
            orientation='vertical',
            spacing=20,
            padding=20
        )
        
        # 
        title = Label(
            text=" Select Video File",
            font_size=48,  # 放大两倍字体
            size_hint_y=None,
            height=80,
            bold=True,
            color=(0.2, 0.6, 0.9, 1)
        )
        main_layout.add_widget(title)
        
        # 
        self.file_chooser = FileChooser()
        self.file_chooser.set_callback(self._on_file_selected)
        main_layout.add_widget(self.file_chooser)
        
        # 
        button_layout = BoxLayout(
            orientation='horizontal',
            size_hint_y=None,
            height=50,
            spacing=10
        )
        
        # 
        back_btn = Button(
            text=" Back",
            size_hint_x=0.3,
            font_size=24  # 放大字体
        )
        back_btn.bind(on_press=self._on_back)
        button_layout.add_widget(back_btn)
        
        # 
        self.process_btn = Button(
            text=" Start Processing",
            size_hint_x=0.7,
            disabled=True,
            font_size=24  # 放大字体
        )
        self.process_btn.bind(on_press=self._on_start_processing)
        button_layout.add_widget(self.process_btn)
        
        main_layout.add_widget(button_layout)
        
        self.add_widget(main_layout)
    
    def _on_file_selected(self, file_path):
        """"""
        if file_path:
            self.selected_file = file_path
            self.process_btn.disabled = False
            self.process_btn.text = f" Process: {file_path.split('/')[-1]}"
        else:
            self.selected_file = None
            self.process_btn.disabled = True
            self.process_btn.text = " Start Processing"
    
    def _on_back(self, instance):
        """"""
        app = App.get_running_app()
        app.navigate_to('main')
    
    def _on_start_processing(self, instance):
        """"""
        if self.selected_file:
            app = App.get_running_app()
            # 
            app.selected_file = self.selected_file
            app.navigate_to('processing')